package wqh.dt;

import cn.tpson.sewercover.core.SewerCoverManager;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

/**
 * Created by devts on 2016/12/22.
 */
public class DynamicServlet extends HttpServlet{

    @Override
    public void destroy() {
        super.destroy();
        SewerCoverManager.getInstance().stopServer();
    }

    @Override
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
        System.out.println("DynamicServlet启动。");
        System.out.println("#######################################################");
        ApplicationContext ac = new FileSystemXmlApplicationContext("classpath:/spring/springmvc-dispatcher.xml");
        DynamicDataCallBack dynamicDataCallBack = (DynamicDataCallBack) ac.getBean("dynamicDataCallBack");
        SewerCoverManager.getInstance().setCallback(dynamicDataCallBack);
        SewerCoverManager sewerCoverManager = SewerCoverManager.getInstance();
        sewerCoverManager.setPort(6000);
        sewerCoverManager.startServer();
    }
}
